package com.example.mq.demotopic;

import com.example.mq.mqclient.Channel;
import com.example.mq.mqclient.Connection;
import com.example.mq.mqclient.ConnectionFactory;
import com.example.mq.mqserver.core.BasicProperties;
import com.example.mq.mqserver.core.ExchangeType;

import java.io.IOException;

/**
 * 用此类来表示一个生产者
 * 该类就表示是一个单独的服务器
 */
public class Producer {
    public static void main(String[] args) throws IOException {
        ConnectionFactory connectionFactory = new ConnectionFactory();
        connectionFactory.setHost("127.0.0.1");
        connectionFactory.setPort(9090);

        Connection connection = connectionFactory.getNewConnection();
        Channel channel = connection.createChannel();
        BasicProperties basicProperties = new BasicProperties();
        basicProperties.setDeliveryMode(2);
        basicProperties.setRoutingKey("");

        boolean ok = false;
        ok = channel.basicPublish("exchange1","bbb.ccc.aaa",basicProperties,"TWS".getBytes());
        ok = channel.basicPublish("exchange1","bbb.ccc.aaa",basicProperties,"TWS".getBytes());
//        ok = channel.basicPublish("exchange1","bbb.ccc",basicProperties,"tws".getBytes());
//        ok = channel.basicPublish("exchange1","bbb.ccc",basicProperties,"TWS".getBytes());
        ok = channel.basicPublish("exchange1","ddd.aaa.bbb.ccc",basicProperties,"TWS".getBytes());
//        ok = channel.basicPublish("exchange1","ddd.ccc",basicProperties,"TWS".getBytes());
//        channel.basicPublish("exchange1","ccc",basicProperties,"Twice".getBytes());
        if(!ok) {
            System.out.println("发送消息失败");
            return;
        }
        System.out.println("发送消息成功");
    }
}
